﻿using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using SimpleTicketBooking.Models.Query;
using SimpleTicketBooking.Models;
using SimpleTicketBooking.Utils.Ext;
using SimpleTicketBooking.Controllers.Base;

namespace SimpleTicketBooking.Controllers
{
    /// <summary>
    /// Tickets resoureces
    /// </summary>
    [ApiVersion((double)ApiVersions.V1)]
    [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
    [ApiController]
    [Route("api/[controller]/v{version:apiVersion}/[action]")]
    public class TicketController : APIControllerBase
    {
        private readonly ILogger<TicketController> _logger;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="logger"></param>
        public TicketController(ILogger<TicketController> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// Get Ticket by ticket Id
        /// </summary>
        /// <param name="Id">Ticket Id</param>
        /// <returns></returns>
        [HttpGet]
        public Ticket GetById(int Id)
        {
            return new Ticket() { 
                Id = 1, 
                EventId=1, 
                CreatedTime=DateTime.Now, 
                Number="T001", 
                IsDeleted=false, 
                OrderId=1, 
                UpdatedTime=DateTime.Now 
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet("myTickets")]
        public IEnumerable<Ticket> GetMyTickets()
        {
            var userId = GetUserId();

            return new List<Ticket>();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet("TicketsByOrderId")]
        public IEnumerable<Ticket> GetTicketsByOrderId(int orderId)
        {
            var userId = GetUserId();

            return new List<Ticket>();
        }

        /// <summary>
        /// Get all users
        /// </summary>
        /// <param name="pageQuery"></param>
        /// <returns></returns>
        [HttpGet(Name = "allTickets")]
        public IEnumerable<Ticket> GetAll([FromQuery] PageQuery pageQuery)
        {
            return new List<Ticket>() { };
        }

        /// <summary>
        /// update user info
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        [HttpPut]
        public bool Update([FromBody] Ticket ticket)
        {
            return true;
        }

        /// <summary>
        /// Add new ticket
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        [HttpPost]
        public bool Add([FromBody] Ticket ticket)
        {
            return true;
        }

        /// <summary>
        /// Delete by Id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool Delete(int Id)
        {
            // TODO: validate input parameters

            // perform logical deletion
            return true;
        }
    }
}
